package com.jic.market.impl;

import com.jic.market.entity.PatchGrouponStockLmtEntity;
import com.jic.market.mapper.PatchGrouponStockLmtEntityMapper;
import com.jic.market.model.LimitQueryUniqueCondition;
import com.jic.market.request.PatchGouponProductRequest;
import com.jic.market.request.PatchGrouponUpdateStockLimitRequest;
import com.jic.market.service.PatchGrouponStockLmtService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author guohuayong
 * @date: 2020年02月26日
 */
@Service
@Slf4j
public class PatchGrouponStockLmtServiceImpl implements PatchGrouponStockLmtService {

    @Resource
    private PatchGrouponStockLmtEntityMapper limitMapper;

    @Override
    public PatchGrouponStockLmtEntity getEntityByPromotionIdAndMpId(Long promotionId, Long mpId) {
        PatchGrouponStockLmtEntity entity = limitMapper.getEntityByPromotionIdAndMpId(promotionId, mpId);
        return entity;
    }

    @Override
    public PatchGrouponStockLmtEntity getEntityLimitQueryUniqueCondition(LimitQueryUniqueCondition condition) {
        PatchGrouponStockLmtEntity entity = limitMapper.getEntityLimitQueryUniqueCondition(condition);
        return entity;
    }

    @Override
    public Integer addPromotionLimitRule(PatchGrouponStockLmtEntity limitEntity) {
        return limitMapper.insert(limitEntity);
    }

    @Override
    public Integer updateByPromotionIdMpId(PatchGouponProductRequest pgpr) {
        PatchGrouponStockLmtEntity param = new PatchGrouponStockLmtEntity();
        param.setRefPatchGrouponTheme(pgpr.getPromotionId());
        param.setMerchantProductId(pgpr.getMpId());
        param.setGrouponPrice(pgpr.getGrouponPrice());
        param.setChannelMerchantLimit(pgpr.getChannelMerchantLimit());
        param.setChannelStoreLimit(pgpr.getChannelStoreLimit());
        param.setIndividualLimit(pgpr.getIndividualLimit());
        param.setOrderLimit(pgpr.getOrderLimit());

        return limitMapper.updateLimit(param);
    }


    @Override
    public Integer updateLimitById(PatchGrouponUpdateStockLimitRequest pgpr) {
        PatchGrouponStockLmtEntity param = new PatchGrouponStockLmtEntity();
        param.setId(pgpr.getLimitRuleId());
        param.setGrouponPrice(pgpr.getGrouponPrice());
        param.setChannelMerchantLimit(pgpr.getChannelMerchantLimit());
        param.setChannelStoreLimit(pgpr.getChannelStoreLimit());
        param.setIndividualLimit(pgpr.getIndividualLimit());
        param.setParentAllocationScale(pgpr.getParentAllocationScale());
        param.setMerchantAllocationScale(pgpr.getMerchantAllocationScale());
        param.setStockLimit(pgpr.getStockLimit());
        param.setOrderLimit(pgpr.getOrderLimit());
        return limitMapper.updateLimitById(param);
    }

    @Override
    public Integer deleteEntityByPromotionIdAndMpId(Long promotionId, Long productId) {
        return limitMapper.deleteEntityByPromotionIdAndMpId(promotionId, productId);
    }

    @Override
    public Integer deleteByPatchGrouponMpId(Long patchGrouponMpId) {
        return limitMapper.deleteByPatchGrouponMpId(patchGrouponMpId);
    }

    @Override
    public List<PatchGrouponStockLmtEntity> findAll(PatchGrouponStockLmtEntity limitEntity) {
        return limitMapper.findAll(limitEntity);
    }

    @Override
    public Integer deleteEntityListByPromotionIdAndStoreIdsBatch(Long promotionId, List<Long> storeIds) {
        return limitMapper.deleteEntityListByPromotionIdAndStoreIdsBatch(promotionId, storeIds);
    }

    @Override
    public Integer insertBatch(List<PatchGrouponStockLmtEntity> list) {
        return limitMapper.insertBatch(list);
    }


}
